<?php
namespace TennisTournament\Form;

use Zend\Form\Element;
use Zend\Form\Form;
use Zend\InputFilter\InputFilter;

class PlayerForm extends Form {

    public function __construct($name = null) {
        parent::__construct('album');

        $this->add(array(
            'name'      =>      'id',
            'type'      =>      'Hidden',
        ));

        $this->add(array(
            'name'      =>      'name',
            'type'      =>      'Text',
            'options'   =>      array(
                'label'     =>      'Add Player\'s name.'
            )
        ));

        $this->add(array(
            'name'      =>      'jobPosition',
            'type'      =>      'Text',
            'options'   =>      array(
                'label'     =>      'Add Player job position.'
            )
        ));

        $this->add(array(
            'name'      =>      'submit',
            'type'      =>      'Submit',
            'attributes'    =>  array(
                'value' =>  'Save Player',
                'id'    =>  'submitButton',
                'class' =>  'btn btn-primary',
            ),
        ));


        $pathToPictureFile = new Element\File('pathToPicture');
        $pathToPictureFile->setAttribute('id', 'pathToPicture');
        $pathToPictureFile->setOptions(array('label' => 'Add Player Picture'));

        $this->add($pathToPictureFile);
    }

    public function getInputFilter() {
        if (parent::getInputFilter() == null) {
            $inputFilter = new InputFilter();

            $inputFilter->add(array(
                'name'      =>      'id',
                'required'  =>      true,
                'filters'   =>      array(
                    array('name' => 'Int'),
                )
            ));

            $inputFilter->add(array(
                'name'      =>      'name',
                'required'  =>      true,
                'filters'   =>      array(
                    array('name' => 'StripTags'),
                    array('name' => 'StringTrim'),
                )
            ));

            $inputFilter->add(array(
                'name'      =>      'jobPosition',
                'required'  =>      true,
                'filters'   =>      array(
                    array('name' => 'StripTags'),
                    array('name' => 'StringTrim'),
                )
            ));

            $this->setInputFilter($inputFilter);
            return $inputFilter;
        }
        return parent::getInputFilter();
    }
}